fix #23262 - [REG v2.113.0-beta.1] ICE when trying to cast a class instance to a C++ interface - #23263
fix #23262 - [REG v2.113.0-beta.1] ICE when trying to cast a class instance to a C++ interface#23263rainers wants to merge 2 commits into
Conversation
…ss instance to a C++ interface no need to exclude C++ classes/interfaces from runtime cast target
|
Thanks for your pull request, @rainers! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
|
@ibuclaw I think I covered your concerns. Still any objections? |
|
I hope you don't need to deal with/break |
dmd crashes when cross-compiling for macos, but I tried LDC on void main()
{
Object obj = new Object;
auto objc = cast(ObjectiveC)(obj);
auto nsstring = cast(NSString)(obj);
auto objc2 = cast(ObjectiveC)(nsstring);
auto obj2 = cast(Object)(nsstring);
}
extern (Objective-C)
extern interface NSString
{
import core.attribute : selector;
const(char)* UTF8String() @selector("UTF8String");
}
extern (Objective-C) class ObjectiveC {}
class classObjC2D : ObjectiveC, NSString
{
extern (Objective-C)
override const(char)* UTF8String() { return null; }
}[casting between extern(C++) and extern(Objective-C) doesn't seem supported.] LDC 1.42 generates calls to _d_cast for all assignments in main, but with LDC 1.41 objc_opt_isKindOfClass, objc_opt_isKindOfClass, object_getClass, class_conformsToProtocol and _d_interface_cast get called. Is this a regression? It still seems this PR might indeed change what LDC does for extern(Objective-C) <-> extern(D) casts. I'm inclined to remove the restriction that the dynamic cast is only used for D -> D/C++, but allow any target interface, no matter what linkage. |
I guess so, although I'm not aware of any filed issues - our extra glue code for that is still in place, but we expect these casts NOT to be lowered to Edit: Or maybe that was/is just an overshooting implementation in LDC, and relying on the D declarations incl. Edit2: Some minimal context in https://github.com/ldc-developers/ldc/pull/4777/changes#r1863875351. I guess this was added to support Swift class/interface stubs (so I guess incomplete/opaque bindings on the D side). But I guess this could all be handled in
Yeah I think that makes sense. |
no need to exclude C++ classes/interfaces from runtime cast target